package com.surfilter.massdata.es.core.model;

import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;

import java.io.IOException;
import java.util.Map;

import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.search.SearchHit;

import com.surfilter.massdata.es.core.entity.EsEntity;

public class EsTopDomainVisits implements EsEntity<TopDomainIndex> {

	/**
	 *  String mappingStr = "{ \"goods\" : { \"properties\": { \"id\": { \"type\": \"long\" }, "
        		                                            + "\"name\": {\"type\": \"string\", \"analyzer\": \"ik_max_word\"}, "
        		                                            + "\"regionIds\": {\"type\": \"string\",\"index\": \"not_analyzed\"}}}}";
	 */
	@Override
	public XContentBuilder createMappingJson(String typeName) throws IOException {
		XContentBuilder mapping = jsonBuilder()
				.startObject()
					.startObject(typeName)
						.startObject("_source").field("enabled", true).endObject()
						.startObject("_all").field("enabled", false).endObject()
							.startObject("properties")
								.startObject("id").field("type","long").endObject()
								.startObject("topDomain").field("type","string").field("index","not_analyzed").endObject()
								.startObject("siteName").field("type","string").field("index","not_analyzed").endObject()
								.startObject("licenseKey").field("type","string").field("index","not_analyzed").endObject()
								.startObject("recordState").field("type","long").endObject()
								.startObject("isBlack").field("type","long").endObject()
								.startObject("isAlive").field("type","long").endObject()
								.startObject("joinCount").field("type","long").endObject()
								.startObject("registrarName").field("type","string").field("index","not_analyzed").endObject()
								.startObject("cnDomainName").field("type","string").field("index","not_analyzed").endObject()
								.startObject("joinUnitIds").field("type","string").field("index","not_analyzed").endObject()
								.startObject("industryType").field("type","string").field("index","not_analyzed").endObject()
								.startObject("industryTypeName").field("type","string").field("index","not_analyzed").endObject()
								.startObject("qzzxSpCjlx").field("type","string").field("index","not_analyzed").endObject()
								.startObject("qzzxSpCjlxName").field("type","string").field("index","not_analyzed").endObject()
								.startObject("findTime").field("type","date").field("format","yyyy-MM-dd HH:mm:ss").endObject()
								.startObject("detectionTime").field("type","date").field("format","yyyy-MM-dd HH:mm:ss").endObject()
								.startObject("sfCdn").field("type","long").field("index","not_analyzed").endObject()
						
								.startObject("ips").field("type","string").field("index","not_analyzed").endObject()
								.startObject("jrsIds").field("type","long").endObject()
								.startObject("jrsMcs").field("type","string").field("index","no").endObject()
								.startObject("idcIspIds").field("type","string").field("index","not_analyzed").endObject()
								.startObject("houseCodes").field("type","string").field("index","not_analyzed").endObject()
								.startObject("shengIds").field("type","long").field("index","no").endObject()
								.startObject("shiIds").field("type","long").field("index","no").endObject()
								.startObject("xianIds").field("type","long").field("index","no").endObject()
								/*.startObject("ips").field("type","string").field("index_name","ip").field("index","not_analyzed").endObject()
								.startObject("jrsIds").field("type","long").field("index_name","jrsId").endObject()
								.startObject("jrsMcs").field("type","string").field("index_name","jrsMc").field("index","no").endObject()
								.startObject("idcIspIds").field("type","string").field("index_name","idcIspId").field("index","not_analyzed").endObject()
								.startObject("houseCodes").field("type","string").field("index_name","houseCode").field("index","not_analyzed").endObject()
								.startObject("shengIds").field("type","long").field("index_name","shengId").field("index","no").endObject()
								.startObject("shiIds").field("type","long").field("index_name","shiId").field("index","no").endObject()
								.startObject("xianIds").field("type","long").field("index_name","xianId").field("index","no").endObject()*/
					.endObject()
				.endObject();
		return mapping;
	}

	@Override
	public XContentBuilder buildEntity(TopDomainIndex entity) throws IOException {
		XContentBuilder source = XContentFactory.jsonBuilder();
				/*.startObject()
					.field("domain", entity.getDomain())
					.field("domain_dns_visits", entity.getDomain_dns_visits())
					.field("domain_idc_visits", entity.getDomain_idc_visits())
					.field("update_time", entity.getUpdate_time())
				.endObject();*/
		return source;
	}

	@Override
	public TopDomainIndex recoveEntity(Map<String, Object> propertiesMap) {
		TopDomainIndex entity = new TopDomainIndex();
		/*for (String key : propertiesMap.keySet()) {
			if ("domain".equals(key)) {
				entity.setDomain((String) propertiesMap.get(key));
			}
			if ("domain_dns_visits".equals(key)) {
				entity.setDomain_dns_visits((String) propertiesMap.get(key));
			}
			if ("domain_idc_visits".equals(key)) {
				entity.setDomain_idc_visits((String) propertiesMap.get(key));
			}
			if ("update_time".equals(key)) {
				entity.setUpdate_time((String) propertiesMap.get(key));
			}
		}*/
		return entity;
	}

	@Override
	public XContentBuilder buildUpdateEntity(TopDomainIndex entity) throws IOException {
		return null;
	}

	@Override
	public TopDomainIndex recoveEntityAndIndex(Map<String, Object> propertiesMap,
			SearchHit arrHits) {
		return null;
	}

}
